﻿Imports System
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Workflow.ComponentModel.Design

Namespace System.Workflow.ComponentModel
    <SRDescription("TerminateActivityDescription"), SRCategory("Standard"), ToolboxItem(GetType(ActivityToolboxItem)), Designer(GetType(TerminateDesigner), GetType(IDesigner)), ToolboxBitmap(GetType(TerminateActivity), "Resources.Terminate.png")> _
    Public NotInheritable Class TerminateActivity
        Inherits Activity
        ' Methods
        Public Sub New()
        End Sub

        Public Sub New(ByVal name As String)
            MyBase.New(name)
        End Sub

        Protected Friend NotOverridable Overrides Function Execute(ByVal executionContext As ActivityExecutionContext) As ActivityExecutionStatus
            executionContext.CloseActivity
            Dim error As String = Me.Error
            executionContext.TerminateWorkflowInstance(New WorkflowTerminatedException([error]))
            Return ActivityExecutionStatus.Closed
        End Function

        Protected Friend Overrides Sub Initialize(ByVal provider As IServiceProvider)
            If (MyBase.Parent Is Nothing) Then
                Throw New InvalidOperationException(SR.GetString("Error_MustHaveParent"))
            End If
            MyBase.Initialize(provider)
        End Sub


        ' Properties
        <Browsable(True), MergableProperty(False), DefaultValue(CStr(Nothing)), SRCategory("Activity"), SRDescription("TerminateErrorMessageDescr")> _
        Public Property [Error] As String
            Get
                Return CStr(MyBase.GetValue(TerminateActivity.ErrorProperty))
            End Get
            Set(ByVal value As String)
                MyBase.SetValue(TerminateActivity.ErrorProperty, value)
            End Set
        End Property


        ' Fields
        Public Shared ReadOnly ErrorProperty As DependencyProperty = DependencyProperty.Register("Error", GetType(String), GetType(TerminateActivity))
    End Class
End Namespace

